#ifndef _MEMORY_HOOKS_H_
#define _MEMORY_HOOKS_H_

#include "iotgo_platformAPI.h"

#if (PLATFORM == PLATFORM_RTL8711)
#define print_memory_heap() \
    printf("\n\r%s(%d), Available heap 0x%x\n", __FUNCTION__, __LINE__, xPortGetFreeHeapSize())
#define pMalloc pvPortMalloc
#define pFree vPortFree

#elif (PLATFORM == PLATFORM_ESP8266)
#define print_system_memory_heap() \
    os_printf("\n\r%s(%d), System available heap 0x%x\n", __FUNCTION__, __LINE__, system_get_free_heap_size())

#define print_rtos_memory_heap() \
    printf("\n\r%s(%d), RTOS available heap 0x%x\n", __FUNCTION__, __LINE__, xPortGetFreeHeapSize())

#define print_memory_heap print_rtos_memory_heap

#define pMalloc malloc
#define pFree free

#elif (PLATFORM == PLATFORM_LINUX)
#define print_memory_heap()
#define print_rtos_memory_heap()
#define pMalloc malloc
#define pFree free

#else
#endif


#if 0 //need to be mv to memory_hooks.c file.
static void *(*pMalloc)(size_t sz) = malloc;
static void (*pFree)(void *ptr) = free;

void poolInitMemoryHooks(MemoryHooks *hooks)
{
    if(!hooks) /* Reset hooks*/
    {
	pMalloc = malloc;
	pFree = free;
    }
    else
    {
	pMalloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc;
	pFree = (hooks->free_fn)?hooks->free_fn:free;
    }
}
#endif

#endif
